from django.db import models
import os
# Create your models here.
class photo(models.Model):
    '''
    相册字段:相册名称
            分类
            图片数量
            创建日期
            地点
            评论
            分享
            备注
    '''
    name = models.CharField(max_length=32,verbose_name='相册名称')
    fenlei = models.CharField(max_length=64,verbose_name='分类')
    add = models.CharField(max_length=256,verbose_name='地址')
    beizhu = models.TextField(verbose_name='备注')
    create_date = models.DateField(auto_now=True,verbose_name='创建时间')
    def PhotoClassName(self):
        photoName = self.__class__.name
        print('033]0;31--------->' + photoName)
        return photoName
    def photoDir(self):
        if os.path.exists('uploadImg/%s' %photo.PhotoClassName):
            print(photo.PhotoClassName)
        else:
            os.mkdir('uploadImg/%s' %photo.PhotoClassName)

    def __str__(self):
        return self.name

class image(models.Model):
    '''
    名称
    简介
    图片日期
    分享
    '''
    img_name = models.CharField(max_length=64,verbose_name='图片名称')
    img = models.ImageField(verbose_name='图片',max_length=4096,default=None,upload_to='uploadImg/%s' %photo.PhotoClassName)
    img_alt = models.TextField(verbose_name='提示')
    photo_name = models.ForeignKey(photo,verbose_name='相册名称')
    img_date = models.TimeField(verbose_name='图片时间')
    def __str__(self):
        return self.img_name
class speak(models.Model):

    '''评论表'''
    image = models.ForeignKey(image)
    author = models.CharField(default='guest',max_length=64)
    data = models.TextField(max_length=128)
    time = models.TimeField(auto_now=True)
    def __str__(self):
        return self.image
